package com.itheima.controllerweb;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckgroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/checkgroup")
public class CheckgroupController {
    @Autowired
    private CheckgroupService checkgroupService;



    //检查组管理  分页查询
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询");
        PageResult pageResult = checkgroupService.findPage(queryPageBean);
        return pageResult;
    }

    //检查组管理 新增
    @PostMapping("/add")
    public Result save(@RequestBody CheckGroup checkgroup){
        log.info("新增检查组");
        checkgroupService.add(checkgroup);
        return new Result(true,"新增成功");
    }

    //检查组管理  修改回显示(根据id查询)
    @GetMapping("/findById")
    public Result findById(@RequestParam ("id") Integer id){
        log.info("回显");
        CheckGroup checkGroup = checkgroupService.findById(id);
        return new Result(true,"查询成功",checkGroup);
    }

    //检查组管理  获取全部检查项信息
    @GetMapping("/findAll")
    public Result findPage(){
        log.info("执行 获取全部检查组 接口");
        List<CheckGroup> checkGroups = checkgroupService.findAll();
        return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroups);
    }


    //检查组管理  修改
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkgroup){
        log.info("修改");
        checkgroupService.update(checkgroup);
        return new Result(true,"修改成功");
    }


    //检查组管理  删除
    @GetMapping("/deleteById")
    public Result delete(@RequestParam("id") Integer id){
        log.info("删除");
        checkgroupService.delete(id);
        return new Result(true,"删除成功");
    }



}
